'use strict';

var gulp = require('gulp');
var rev = require('gulp-rev');
var gulpif = require('gulp-if');
var $ = require('gulp-load-plugins')();
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var config = require('../config');
var env = require('../utils/env');
var handleErrors = require('../utils/handleErrors');

// js压缩,生成MD5、sourcemap
gulp.task('js', function() {
    return gulp.src(config.js.src).pipe(gulpif(env() === 'development', sourcemaps.init())).pipe(concat('ballon.js', {newLine: ';'})).pipe($.babel({presets: ['es2015']})).pipe(uglify()).pipe(rev()).pipe(gulp.dest(config.js.dest)).pipe(gulpif(env() === 'development', sourcemaps.write('.', {includeContent: false}))).pipe(gulpif(env() === 'development', gulp.dest(config.js.dest))).pipe(rev.manifest()).on('error', handleErrors).pipe(gulp.dest(config.js.dest));
});
